package com.yycwxt.modules.admin.store;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.read.listener.ReadListener;
import com.yycwxt.common.BaseService;
import com.yycwxt.domain.Store;
import lombok.SneakyThrows;
import org.apache.commons.compress.utils.Lists;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Service
@Transactional
public class StoreService2 extends BaseService<StoreMapper, Store> {
//    @SneakyThrows
//    @Transactional
//    public boolean importFileToDB(boolean deleteHistory, MultipartFile file) {
//        if (deleteHistory) {
//            this.remove(null);
//        }
//        EasyExcel.read(file.getInputStream(), Store.class, new ReadListener<Store>() {
//
//            private static final int BATCH_SIZE = 1000;
//            private List<Store> ls = Lists.newArrayList();
//
//            @Override
//            public void invoke(Store data, AnalysisContext context) {
//                // System.out.println(data);
//                ls.add(data);
//                if (ls.size() >= BATCH_SIZE) {
//                    StoreService2.this.saveBatch(ls);
//                    ls.clear();
//                }
//            }
//
//            @Override
//            public void doAfterAllAnalysed(AnalysisContext context) {
//                StoreService2.this.saveBatch(ls);
//            }
//        }).sheet().doRead();
//        return true;
//    }
}
